package com.youlai.boot.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.boot.system.mapper.HygienesMapper;
import com.youlai.boot.system.model.QB.Hygienes;
import com.youlai.boot.system.service.HygienesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class HygienesServiceImpl extends ServiceImpl<HygienesMapper, Hygienes> implements HygienesService {
    @Autowired
    private HygienesMapper hygienesMapper;
    @Override
    public boolean saveHygienes(Hygienes basc) {
        basc.setAddtime(LocalDateTime.now());
        if (basc.getPicUrls() != null && basc.getPicUrls().size() > 0){
            String picUrl = "";
            for (String str : basc.getPicUrls()){
                picUrl += str + ",";
            }
            if (org.apache.commons.lang3.StringUtils.isNotBlank(picUrl)){
                picUrl = picUrl.substring(0,picUrl.length()-1);
            }
            basc.setPicUrl(picUrl);
        }
        return save(basc);
    }


    @Override
    public List<Hygienes> getAllHygienes() {
        return hygienesMapper.selectList(null);
    }

    @Override
    public boolean deleteHygienesById(Integer id) {
        return baseMapper.deleteById(id) >0;
    }
}
